package edison.jcr.nodetype;

import javax.jcr.nodetype.ItemDefinition;
import javax.jcr.nodetype.NodeType;
import edison.jcr.SessionContext;
import edison.persistence.NodeTypeBean;
import edison.persistence.QueryUtils;

public abstract class ItemDefinitionImpl implements ItemDefinition {

	protected String name;
	protected boolean isAutoCreated;
	protected boolean isMandatory;
	protected int onParentVersionAction;
	protected boolean isProtected;
	protected String declaringNodeTypeName;
	protected final SessionContext context;

	ItemDefinitionImpl(SessionContext context) {
		this.context = context;
	}

	public NodeType getDeclaringNodeType() {
		NodeTypeBean nodeTypeBean = QueryUtils.getNodeType(context.getEntityManager(), declaringNodeTypeName);
		return new NodeTypeImpl(context, nodeTypeBean);
	}

	public String getName() {
		return name;
	}

	public boolean isAutoCreated() {
		return isAutoCreated;
	}

	public boolean isMandatory() {
		return isMandatory;
	}

	public int getOnParentVersion() {
		return onParentVersionAction;
	}

	public boolean isProtected() {
		return isProtected;
	}

}